package com.handpay.zztong.hp.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.handpay.framework.utils.CommonUtils;
import com.handpay.framework.utils.DateUtils;
import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.bean.WithdrawRecordsBill;
import com.handpay.zztong.hp.withdraw.bean.QueryWithdrawRecordBean;

public class WithDrawRecordsAdapter extends BaseAdapter {
    private List<QueryWithdrawRecordBean.WithdrawBody> withDrawBills=new ArrayList<>();
    private LayoutInflater inflater;

    public WithDrawRecordsAdapter(Context activity) {
        inflater = LayoutInflater.from(activity);
    }

    public void setWithDrawBills(List<QueryWithdrawRecordBean.WithdrawBody> withDrawBills) {
        this.withDrawBills = withDrawBills;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return withDrawBills==null?0:withDrawBills.size();
    }
    public void clear(){
        this.withDrawBills.clear();
        this.notifyDataSetChanged();
    }
    @Override
    public Object getItem(int position) {
        return this.withDrawBills.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ZuJian zuJian = null;
        if (convertView == null) {
            zuJian = new ZuJian();
            convertView = inflater.inflate(R.layout.withdrawrecords, null);
            zuJian.withdrawapplytime = (TextView) convertView.findViewById(R.id.withdrawtimetv);
            zuJian.withdrawstatus = (TextView) convertView.findViewById(R.id.withdrawstatus);
            zuJian.ll_applyWithdrawAmount = (LinearLayout) convertView.findViewById(R.id.applyWithdrawAmountll);
            zuJian.applyWithdrawAmount = (TextView) convertView.findViewById(R.id.applyWithdrawAmount);
            zuJian.ll_actualWithdrawAmount = (LinearLayout) convertView.findViewById(R.id.actualWithdrawAmountll);
            zuJian.actualWithdrawAmount = (TextView) convertView.findViewById(R.id.actualWithdrawAmount);
            convertView.setTag(zuJian);
        } else {
            zuJian = (ZuJian) convertView.getTag();
        }
        QueryWithdrawRecordBean.WithdrawBody bills = withDrawBills.get(position);
        zuJian.withdrawapplytime.setText(DateUtils.formatDateToString(
                DateUtils.formatStringToDate(bills.getRwdTime(), "yyyyMMddHHmmss"), "yyyyMMdd HH:mm:ss"));
        zuJian.withdrawstatus.setText(bills.getRwdDes());

        int wdStatus = CommonUtils.objectToInt(bills.getRwdStatus());
        //提现申请失败、提现失败，字体为红色。否则为黑色
        if (WithdrawRecordsBill.STATUS_FAILED == wdStatus || WithdrawRecordsBill.STATUS_WD_FAIL == wdStatus) {
            zuJian.withdrawstatus.setTextColor(Color.RED);
        } else {
            zuJian.withdrawstatus.setTextColor(Color.BLACK);
        }
        //提现成功的时候，才显示实际金额。
        if (WithdrawRecordsBill.STATUS_WD_SUCCESS == wdStatus) {
            zuJian.ll_actualWithdrawAmount.setVisibility(View.VISIBLE);
        } else {
            zuJian.ll_actualWithdrawAmount.setVisibility(View.GONE);
        }
        zuJian.applyWithdrawAmount.setText(CommonUtils.formatMoney(CommonUtils.objectToDouble(bills.getRwdMoney()) / 100));
        zuJian.actualWithdrawAmount.setText(CommonUtils.formatMoney(CommonUtils.objectToDouble(bills.getWdMoney()) / 100));
        return convertView;
    }

    public static class ZuJian {
        private TextView withdrawapplytime = null;
        private TextView withdrawstatus = null;
        private LinearLayout ll_applyWithdrawAmount;
        private LinearLayout ll_actualWithdrawAmount;
        private TextView applyWithdrawAmount = null;
        private TextView actualWithdrawAmount = null;
    }

}
